home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / htmlclue.h.z / htmlclue.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  14.7 KB  |  453 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Martin Jones (mjones@kde.org)
  3.               (C) 1997 Torben Weis (weis@kde.org)
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18.     Boston, MA 02111-1307, USA.
  19. */
  20. //-----------------------------------------------------------------------------
  21. //
  22. // KDE HTML Widget
  23. //
  24.  
  25. #ifndef HTMLCLUE_H
  26. #define HTMLCLUE_H
  27.  
  28. #include <qpainter.h>
  29. #include <qlist.h>
  30. #include <qstrlist.h>
  31. #include <qarray.h>
  32. #include <qpixmap.h>
  33. #include <qstack.h>
  34. #include <qfont.h>
  35. #include <qtimer.h>
  36.  
  37. #include <kurl.h>
  38.  
  39. class HTMLClueV;
  40. class HTMLImage;
  41. class HTMLClue;
  42. class HTMLClueFlow;
  43. class HTMLClueAligned;
  44. class KHTMLWidget;
  45.  
  46. #include "htmlfont.h"
  47. #include "htmlobj.h"
  48.  
  49. // The border around an aligned object
  50. #define ALIGN_BORDER 0
  51.  
  52. class HTMLAnchor;
  53.  
  54. //-----------------------------------------------------------------------------
  55. // Clues are used to contain and format objects (or other clues).
  56. // This is the base of all clues - it should be considered abstract.
  57. //
  58. class HTMLClue : public HTMLObject
  59. {
  60. public:
  61.     /************************************************************
  62.      * This class is abstract. Do not instantiate it. The _y argument
  63.      * is always 0 yet. _max_width defines the width you allow this Box
  64.      * to have. If you do not use HCenter or Right and if this Box
  65.      * becomes a child of a VBox you may set _x to give this Box
  66.      * a shift to the right.
  67.      *
  68.      * if:
  69.      *     _percent == -ve     width = best fit
  70.      *     _percent == 0       width = _max_width (fixed)
  71.      *     _percent == +ve     width = _percent * 100 / _max_width
  72.      */
  73.     HTMLClue( int _x, int _y, int _max_width, int _percent = 100);
  74.     virtual ~HTMLClue();
  75.  
  76.     virtual int  findPageBreak( int _y );
  77.     virtual bool print( QPainter *_painter, int _x, int _y, int _width,
  78.         int _height, int _tx, int _ty, bool toPrinter );
  79.     /// Prints a special object only
  80.     /**
  81.      * This function is for example used to redraw an image that had to be
  82.      * loaded from the world wide wait.
  83.      */
  84.     virtual void print( QPainter *_painter, HTMLObject *_obj, int _x, int _y,
  85.         int _width, int _height, int _tx, int _ty );
  86.     virtual void print( QPainter *, int _tx, int _ty );
  87.     /************************************************************
  88.      * Calls all children and tells them to calculate their size.
  89.      */
  90.     virtual void calcSize( HTMLClue *parent = 0L );
  91.     virtual void recalcBaseSize( QPainter * );
  92.     virtual int  calcMinWidth();
  93.     virtual int  calcPreferredWidth();
  94.     virtual void setMaxAscent( int );
  95.     virtual HTMLObject *checkPoint( int, int );
  96.     virtual HTMLObject *mouseEvent( int, int, int, int );
  97.     virtual void selectByURL( QPainter *,const char *,bool, int _tx, int _ty );
  98.     virtual void select( QPainter *_painter, QRegExp& _pattern, bool _select,
  99.         int _tx, int _ty );
  100.     virtual void select( QPainter *, bool, int _tx, int _ty );
  101.     /*
  102.      * Selects every objectsin this clue if it is inside the rectangle
  103.      * and deselects it otherwise.
  104.      */
  105.     virtual void select( QPainter *, QRect &_rect, int _tx, int _ty );
  106.     virtual void select( bool );
  107.     virtual void getSelected( QStrList & );
  108.     virtual bool selectText( QPainter *_painter, int _x1, int _y1,
  109.                  int _x2, int _y2, int _tx, int _ty );
  110.     virtual void getSelectedText( QString & );
  111.  
  112.     virtual void calcAbsolutePos( int _x, int _y );
  113.     virtual void setIndent( int ) { }
  114.     virtual void reset();
  115.  
  116.     virtual ObjectType getObjectType() const
  117.         {    return Clue; }
  118.     bool hasChildren() const
  119.         {    return (head != 0L); }
  120.  
  121.     /************************************************************
  122.      * Make an object a child of this Box.
  123.      */
  124.     void append( HTMLObject *_object )
  125.     {
  126.         if ( !head )
  127.         {
  128.         head = tail = _object;
  129.         }
  130.         else
  131.         {
  132.         tail->setNext( _object );
  133.         tail = _object;
  134.         }
  135.     }
  136.     
  137.     virtual void findFreeArea( int _y, int, int, int,
  138.                                int *_y_pos, int *_lmargin, int *_rmargin)
  139.         { *_y_pos = _y; *_lmargin = 0; *_rmargin = max_width; }
  140.     // This method tries to find a free rectangular area of _width x _height
  141.     // from position _y on. The start of this area is written in *y_pos.
  142.     // The actual left and right margins of the area are returned in
  143.     // *lmargin and *rmargin.
  144.     virtual void appendLeftAligned( HTMLClueAligned * ) { }
  145.     virtual void appendRightAligned( HTMLClueAligned * ) { }
  146.     virtual int  appended(HTMLClueAligned * ) { return 0;}
  147.     virtual void removeAlignedByParent( HTMLObject * ) { }
  148.     virtual int  getLeftMargin( int )
  149.         { return 0; }
  150.     virtual int  getRightMargin( int )
  151.     { return max_width; }
  152.     virtual int  getLeftClear( int _y )
  153.     { return _y; }
  154.     virtual int  getRightClear( int _y )
  155.     { return _y; }
  156.     
  157.     void setVAlign( VAlign _v ) { valign = _v; }
  158.     void setHAlign( HAlign _h ) { halign = _h; }
  159.     VAlign getVAlign() { return valign; }
  160.     HAlign getHAlign() { return halign; }
  161.  
  162.     virtual HTMLAnchor* findAnchor( const char *_name, QPoint *_p );
  163.  
  164.     virtual void findCells( int _tx, int _ty, QList<HTMLCellInfo> &_list );
  165.   
  166. protected:
  167.     HTMLObject *head;
  168.     HTMLObject *tail;
  169.     HTMLObject *curr;
  170.  
  171.     VAlign valign;
  172.     HAlign halign;
  173. };
  174.  
  175. //-----------------------------------------------------------------------------
  176. // Used for aligning images etc. to the left or right of the page.
  177. //
  178. class HTMLClueAligned : public HTMLClue
  179. {
  180. public:
  181.     HTMLClueAligned( HTMLClue *_parent, int _x, int _y, int _max_width,
  182.              int _percent = 100 )
  183.     : HTMLClue( _x, _y, _max_width, _percent )
  184.     { prnt = _parent; nextAligned = 0; setAligned( true ); }
  185.     virtual ~HTMLClueAligned() { }
  186.     
  187.     virtual void setMaxWidth( int );
  188.     virtual void setMaxAscent( int ) { }
  189.     virtual void calcSize( HTMLClue *_parent = 0L );
  190.     
  191.     HTMLClue *parent()
  192.     { return prnt; }
  193.     HTMLClueAligned *nextClue() const
  194.     { return nextAligned; }
  195.     void setNextClue( HTMLClueAligned *n )
  196.     { nextAligned = n; }
  197.     
  198. private:
  199.     HTMLClue *prnt;
  200.     HTMLClueAligned *nextAligned;
  201. };
  202.  
  203. //-----------------------------------------------------------------------------
  204. // Align objects across the page, wrapping at the end of a line
  205. //
  206. class HTMLClueFlow : public HTMLClue
  207. {
  208. public:
  209.     HTMLClueFlow( int _x, int _y, int _max_width, int _percent=100)
  210.         : HTMLClue( _x, _y, _max_width, _percent ) { indent = 0; }
  211.     virtual ~HTMLClueFlow() { }
  212.     
  213.     virtual bool selectText( QPainter *_painter, int _x1, int _y1,
  214.         int _x2, int _y2, int _tx, int _ty );
  215.     virtual void getSelectedText( QString & );
  216.     virtual void calcSize( HTMLClue *parent = 0L );
  217.     virtual int  findPageBreak( int _y );
  218.     virtual int  calcMinWidth();
  219.     virtual int  calcPreferredWidth();
  220.     virtual void setMaxWidth( int );
  221.  
  222.     virtual void setIndent( int i )
  223.         {    indent = i; }
  224.  
  225. protected:
  226.     short indent;
  227. };
  228.  
  229. //-----------------------------------------------------------------------------
  230. // Align objects vertically
  231. //
  232. class HTMLClueV : public HTMLClue
  233. {
  234. public:
  235.     HTMLClueV( int _x, int _y, int _max_width, int _percent = 100 );
  236.     virtual ~HTMLClueV() { }
  237.  
  238.     virtual void reset();
  239.  
  240.     virtual void setMaxWidth( int );
  241.     virtual HTMLObject *checkPoint( int, int );
  242.     virtual HTMLObject *mouseEvent( int, int, int, int );
  243.     virtual void calcSize( HTMLClue *parent = 0L );
  244.     virtual bool print( QPainter *_painter, int _x, int _y, int _width,
  245.         int _height, int _tx, int _ty, bool toPrinter );
  246.     virtual void print( QPainter *_painter, HTMLObject *_obj, int _x, int _y,
  247.         int _width, int _height, int _tx, int _ty )
  248.     { HTMLClue::print(_painter,_obj,_x,_y,_width,_height,_tx,_ty); }
  249.  
  250.     virtual void findFreeArea( int _y, int _width, int _height, int _indent,
  251.                                int *_y_pos, int *_lmargin, int *_rmargin);
  252.     // This method tries to find a free rectangular area of _width x _height
  253.     // from position _y on. The start of this area is written in *y_pos.
  254.     // The actual left and right margins of the area are returned in
  255.     // *lmargin and *rmargin.
  256.                    
  257.     virtual void appendLeftAligned( HTMLClueAligned *_clue );
  258.     virtual void appendRightAligned( HTMLClueAligned *_clue );
  259.     virtual int  appended(HTMLClueAligned * );
  260.     virtual int  getLeftMargin( int _y );
  261.     virtual int  getRightMargin( int _y );
  262.     virtual int  getLeftClear( int _y );
  263.     virtual int  getRightClear( int _y );
  264.   
  265. protected:
  266.     void removeAlignedByParent( HTMLObject *p );
  267.  
  268. protected:
  269.     // These are the objects which are left or right aligned within this
  270.     // clue.  Child objects must wrap their contents around these.
  271.     HTMLClueAligned *alignLeftList;
  272.     HTMLClueAligned *alignRightList;
  273. };
  274.  
  275. /**
  276.  * Used for KFMs HTML extension
  277.  */
  278. class HTMLCell : public HTMLClueV
  279. {
  280. public:
  281.   HTMLCell( int _x, int _y, int _max_width, int _percent = 100, const char *_url = 0L, const char *_target = 0L );
  282.   virtual ~HTMLCell() { }
  283.   
  284.   virtual const char* getURL() const { return url; }
  285.   virtual const char* getTarget() const { return target; }
  286.  
  287.   virtual void select( QPainter *, QRect &_rect, int _tx, int _ty );
  288.  
  289.   virtual bool print( QPainter *_painter, int _x, int _y, int _width,
  290.               int _height, int _tx, int _ty, bool toPrinter );
  291.  
  292.   virtual bool isMarked() { return bIsMarked; }
  293.   virtual void setMarker( QPainter *_painter, int _tx, int _ty, bool _mode );
  294.   virtual void findCells( int _tx, int _ty, QList<HTMLCellInfo> &_list );
  295.  
  296. protected:
  297.   const char *url;
  298.   const char *target;
  299.  
  300.   bool bIsMarked;
  301. };
  302.  
  303. //-----------------------------------------------------------------------------
  304. // Align objects across the page, without wrapping.
  305. // This clue is required for lists, etc. so that tables can dynamically
  306. // change max_width and have the contents' max_widths changed appropriately.
  307. // Also used by <pre> lines
  308. //
  309. class HTMLClueH : public HTMLClue
  310. {
  311. public:
  312.     HTMLClueH( int _x, int _y, int _max_width, int _percent = 100 )
  313.         : HTMLClue( _x, _y, _max_width, _percent ) { indent = 0; }
  314.     virtual ~HTMLClueH() { }
  315.     
  316.     virtual bool selectText( QPainter *_painter, int _x1, int _y1,
  317.         int _x2, int _y2, int _tx, int _ty );
  318.     virtual void setMaxWidth( int );
  319.     virtual void calcSize( HTMLClue *parent = 0L );
  320.     virtual int  calcMinWidth();
  321.     virtual int  calcPreferredWidth();
  322.  
  323.     virtual void setIndent( int i )
  324.         {    indent = i; }
  325.  
  326. private:
  327.     short indent;
  328. };
  329.  
  330.  
  331. //-----------------------------------------------------------------------------
  332. // really only useful for tables.
  333. //
  334. class HTMLTableCell : public HTMLClueV
  335. {
  336. public:
  337.     HTMLTableCell( int _x, int _y, int _max_width, int _percent,
  338.         int rs, int cs, int pad );
  339.     virtual ~HTMLTableCell() { }
  340.  
  341.     int rowSpan() const
  342.         {    return rspan; }
  343.     int colSpan() const
  344.         {    return cspan; }
  345.     const QColor &bgColor() const
  346.         {    return bg; }
  347.  
  348.     void setBGColor( const QColor &c )
  349.         {    bg = c; }
  350.  
  351.     virtual void setMaxWidth( int );
  352.     virtual int  calcMinWidth();
  353.     virtual bool print( QPainter *_painter, int _x, int _y, int _width,
  354.         int _height, int _tx, int _ty, bool toPrinter );
  355.     virtual void print( QPainter *_painter, HTMLObject *_obj, int _x, int _y,
  356.         int _width, int _height, int _tx, int _ty )
  357.     { HTMLClueV::print(_painter,_obj,_x,_y,_width,_height,_tx,_ty); }
  358.  
  359. protected:
  360.     int rspan;
  361.     int cspan;
  362.     int padding;
  363.     QColor bg;
  364. };
  365.  
  366. //-----------------------------------------------------------------------------
  367. //
  368. class HTMLTable : public HTMLObject
  369. {
  370. public:
  371.     HTMLTable( int _x, int _y, int _max_width, int _width, int _percent,
  372.         int _padding = 1, int _spacing = 2, int _border = 0 );
  373.     virtual ~HTMLTable();
  374.  
  375.     void startRow();
  376.     void addCell( HTMLTableCell *cell );
  377.     void endRow();
  378.     void endTable();
  379.  
  380.     void setCaption( HTMLClueV *cap, HTMLClue::VAlign al )
  381.         {    caption = cap; capAlign = al; }
  382.  
  383.     virtual void reset();
  384.     virtual void calcSize( HTMLClue *parent = 0L );
  385.     virtual int  calcMinWidth();
  386.     virtual int  calcPreferredWidth();
  387.     virtual void setMaxWidth( int _max_width );
  388.     virtual void setMaxAscent( int );
  389.     virtual HTMLObject *checkPoint( int, int );
  390.     virtual HTMLObject *mouseEvent( int, int, int, int );
  391.     virtual void selectByURL( QPainter *,const char *, bool, int _tx, int _ty );
  392.     virtual void select( QPainter *_painter, QRegExp& _pattern, bool _select,
  393.         int _tx, int _ty );
  394.     virtual void select( QPainter *, bool, int _tx, int _ty );
  395.     /**
  396.      * Selects every object in this table if it is inside the rectangle
  397.      * and deselects it otherwise.
  398.      */
  399.     virtual void select( QPainter *, QRect &_rect, int _tx, int _ty );
  400.     virtual void select( bool );
  401.     virtual bool selectText( QPainter *_painter, int _x1, int _y1,
  402.         int _x2, int _y2, int _tx, int _ty );
  403.     virtual void getSelected( QStrList & );
  404.     virtual void getSelectedText( QString & );
  405.  
  406.     virtual void calcAbsolutePos( int _x, int _y );
  407.  
  408.     virtual ObjectType getObjectType() const
  409.         {    return Clue; }
  410.  
  411.     virtual HTMLAnchor *findAnchor( const char *_name, QPoint *_p );
  412.  
  413.     virtual int  findPageBreak( int _y );
  414.     virtual bool print( QPainter *_painter, int _x, int _y, int _width,
  415.             int _height, int _tx, int _ty, bool toPrinter );
  416.     virtual void print( QPainter *_painter, HTMLObject *_obj, int _x, int _y,
  417.         int _width, int _height, int _tx, int _ty );
  418.     virtual void print( QPainter *, int _tx, int _ty );
  419.  
  420.     virtual void findCells( int _tx, int _ty, QList<HTMLCellInfo> &_list );
  421.   
  422. protected:
  423.     void setCells( unsigned int r, unsigned int c, HTMLTableCell *cell );
  424.     void calcColumnWidths();
  425.     void optimiseCellWidth();
  426.     void scaleColumns(unsigned int c_start, unsigned int c_end, int tooAdd);
  427.     void calcRowHeights();
  428.     void addRows( int );
  429.     void addColumns( int );
  430.  
  431. protected:
  432.     enum ColType { Fixed, Percent, Variable };
  433.     HTMLTableCell ***cells;
  434.     QArray<int> columnPos;
  435.     QArray<int> columnPrefPos;
  436.     QArray<int> columnOpt;
  437.     QArray<int> colSpan;
  438.     QArray<int> rowHeights;
  439.     QArray<ColType> colType;
  440.     unsigned int col, totalCols;
  441.     unsigned int row, totalRows, allocRows;
  442.     int spacing;
  443.     int padding;
  444.     int border;
  445.     HTMLClueV *caption;
  446.     HTMLClue::VAlign capAlign;
  447. };
  448.  
  449. //-----------------------------------------------------------------------------
  450.  
  451. #endif // HTMLCLUE_H
  452.  
  453.